package com.ruoyi.college.service.impl;

import java.util.List;

import com.ruoyi.college.domain.College;
import com.ruoyi.college.domain.Major;
import com.ruoyi.college.service.ICollegeService;
import com.ruoyi.college.service.IMajorService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.college.mapper.ClassMapper;
import com.ruoyi.college.domain.Class;
import com.ruoyi.college.service.IClassService;
import com.ruoyi.common.core.text.Convert;

/**
 * 班级信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@Service
public class ClassServiceImpl implements IClassService 
{
    @Autowired
    private ClassMapper classMapper;

    @Autowired
    private ICollegeService collegeService;

    @Autowired
    private IMajorService majorService;

    /**
     * 查询班级信息
     * 
     * @param classId 班级信息主键
     * @return 班级信息
     */
    @Override
    public Class selectClassByClassId(Long classId)
    {
        return classMapper.selectClassByClassId(classId);
    }

    /**
     * 查询班级信息列表
     * 
     * @param class 班级信息
     * @return 班级信息
     */
    @Override
    public List<Class> selectClassList(Class cla)
    {
        List<Class> classes = classMapper.selectClassList(cla);
        classes.forEach(c->{
            Integer collegeId = c.getCollegeId();
            College college = collegeService.selectCollegeByCollegeId(Long.parseLong(String.valueOf(collegeId)));
            c.setCollegeName(college.getCollegeName());
            Major major = majorService.selectMajorByMajorId(Long.parseLong(String.valueOf(c.getMajorId())));
            c.setMajorName(major.getMajorName());
        });
        return classes;
    }

    /**
     * 新增班级信息
     * 
     * @param class 班级信息
     * @return 结果
     */
    @Override
    public int insertClass(Class cla)
    {
        cla.setCreateTime(DateUtils.getNowDate());
        return classMapper.insertClass(cla);
    }

    /**
     * 修改班级信息
     * 
     * @param class 班级信息
     * @return 结果
     */
    @Override
    public int updateClass(Class cla)
    {
        return classMapper.updateClass(cla);
    }

    /**
     * 批量删除班级信息
     * 
     * @param classIds 需要删除的班级信息主键
     * @return 结果
     */
    @Override
    public int deleteClassByClassIds(String classIds)
    {
        return classMapper.deleteClassByClassIds(Convert.toStrArray(classIds));
    }

    /**
     * 删除班级信息信息
     * 
     * @param classId 班级信息主键
     * @return 结果
     */
    @Override
    public int deleteClassByClassId(Long classId)
    {
        return classMapper.deleteClassByClassId(classId);
    }
}
